package com.rfid.emergencywarehouse.presenter;

import com.rfid.emergencywarehouse.entity.AssetOrderDetail;
import com.rfid.emergencywarehouse.net.NetApi;
import com.rfid.emergencywarehouse.net.entity.EnterWorkArea;
import com.rfid.emergencywarehouse.net.entity.GetOrderDetailRes;
import com.rfid.emergencywarehouse.view.IGetAssetWithOrderView;

import java.io.IOException;

public class GetAssetWithOrderPresenter extends GetAssetPresenter<IGetAssetWithOrderView> {

    public void getOrderDetail(String id) {
        mExcutor.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    GetOrderDetailRes res = NetApi.INSTANCE.getGetOrderDetail(id);
                    if (res.getCode() == 0) {
                        GetOrderDetailRes.DataBean bean = res.getData();
                        AssetOrderDetail detail = new AssetOrderDetail();
                        detail.setBarCodePickedCount(bean.getBarCodePickedCount());
                        detail.setBarCodePickingCount(bean.getBarCodePickingCount());
                        detail.setBarCodeTotalCount(bean.getBarCodeTotalCount());
                        detail.setCreateTime(bean.getCreateTime());
                        detail.setOriginOrderNo(bean.getOriginOrderNo());
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (mView != null) {
                                    mView.onOrderDetail(detail);
                                }
                            }
                        });
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    public void postEnterStatus(String workAreaId,String outOrderId) {
        mExcutor.execute(new Runnable() {
            @Override
            public void run() {
                EnterWorkArea req = new EnterWorkArea();
                req.setWorkAreaId(workAreaId);
                req.setOutOrderId(outOrderId);
                try {
                    NetApi.INSTANCE.postEnterStatus(req);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    public void exitWorkArea(String workAreaId,String outOrderId) {
        mExcutor.execute(new Runnable() {
            @Override
            public void run() {
                EnterWorkArea req = new EnterWorkArea();
                req.setWorkAreaId(workAreaId);
                req.setOutOrderId(outOrderId);
                try {
                    NetApi.INSTANCE.postEnterStatus(req);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
